<?php

namespace app\admin\model;

use think\Model;


class Material extends Model
{





    // 表名
    protected $name = 'material';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'sex_text'
    ];



    public function getSexList()
    {
        return ['men' => __('男'), 'women' => __('女')];
    }


    public function getSexTextAttr($value, $data)
    {
        $value = $value ?: ($data['sex'] ?? '');
        $valueArr = explode(',', $value);
        $list = $this->getSexList();
        return implode(',', array_intersect_key($list, array_flip($valueArr)));
    }

    protected function setSexAttr($value)
    {
        return is_array($value) ? implode(',', $value) : $value;
    }
    public function user()
    {
        return $this->belongsTo(User::class, 'uid', 'id', [], 'LEFT')->setEagerlyType(0);
    }

}
